package com.yuneec.droneservice.command;

import com.MAVLink.yuneec.msg_mav_rc_cmd_ack;
import com.yuneec.droneservice.request.IResponse;
import com.yuneec.droneservice.utils.ByteUtils;

/**
 * Created by gjw on 2017/3/27.
 */

public class SetChannelFormula extends BaseCommand {
    private final byte[] data;

    public SetChannelFormula(int index, int[] formula) {
        super(MAV_RC_COMMAND.MAV_RC_CMD_SET_CH_CURVE);
        data = new byte[1 + 2 * formula.length];
        data[0] = (byte) index;
        for (int i = 0; i < formula.length; i++) {
            ByteUtils.uShortToByteArray(data, 1 + 2 * i, formula[i], IS_BIGENDIAN);
        }
    }

    @Override
    protected short[] body() {
        short[] body = new short[data.length];
        byteArrayToUIntArray(body, 0, data, 0);
        return body;
    }

    @Override
    public IResponse toResponse(msg_mav_rc_cmd_ack ack) {
        int code = ack.code;
        return new IResponse(ids(), code);
    }
}
